package com.tedu.spring.di;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * 在userservice类中，注入userdao对象；
 */
@Service
public class UserService {
    @Value("Lucy")
    private String username;
    @Value("123")
    private String password;
    /*
         Autowired注解：自动装配注解;
         1.作用：注入对象类型或者接口类型的数据;
         2.添加位置:
           2.1 添加在属性上; 常用方法
           2.2 添加在set方法上;
           2.3 添加在构造方法上;
      */
    @Autowired
    private UserDao userDao; //对象或者接口类型，无法使用Value进行注入,需要使用@Autowired进行注入

    @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Autowired
    public UserService(UserDao userDao) {
        System.out.println("UserService()....");
        this.userDao = userDao;
    }

    @Override
    public String toString() {
        return "UserService [username=" + username + ", password=" + password
                + ", userDao=" + userDao + "]";
    }

}
